package com.wjw.java.io;

import java.io.File;
import java.io.IOException;

/**
 * 创建文件：三种方式
 */
public class FileCreate {

    public static void main(String[] args) {
        //create1();
        //create2();
        create3();
    }

    /**
     * 1.根据文件的全路径,创建
     */
    public static void create1(){
        String filePath = "f:\\1.txt";
        File file = new File(filePath);
        try {
            file.createNewFile();
            System.out.println("文件创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 2.根据父目录文件 +子路径,创建
     */
    public static void create2(){
        File parentFile = new File("f:\\");
        String sonFileName = "2.txt";
        File file = new File(parentFile, sonFileName);
        try {
            file.createNewFile();
            System.out.println("文件创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 3.根据父目录路径 +子路径,创建
     */
    public static void create3(){
        String parentFilePath = "f:\\";
        String sonFilePath = "3.txt";
        File file = new File(parentFilePath,sonFilePath);
        try {
            file.createNewFile();
            System.out.println("文件创建成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
